package com.zhx.basis.juc;

public class ThreadLocal学习 {
    public static void main(String[] args) {
        ThreadLocal<String> threadLocal=new ThreadLocal<>();
        ThreadLocal<String> threadLocal2=new ThreadLocal<>();
        for (int i = 0; i <10 ; i++) {
            int finalI = i;
            new Thread(new Runnable() {
                @Override
                public void run() {
                    if (finalI%2==0){
                        threadLocal.set("当前线程"+ finalI);
                        System.out.println(threadLocal.get());
                        threadLocal.remove();
                    }else{
                        threadLocal2.set("当前线程"+ finalI);
                        System.out.println(threadLocal2.get());
                        threadLocal2.remove();
                    }

                }
            }).start();
        }
    }
}
